package com.wgchao.identityrightsmanagement.infrastructure.convert;

import com.wgchao.identityrightsmanagement.domain.organization.model.Account;
import com.wgchao.identityrightsmanagement.infrastructure.jpa.entity.SysBaseAccount;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

/**
 * @ClassName: AccountConvert
 * @author: wgchao
 * @createTime: 2020/6/12 11:06 AM
 * @Description: TODO
 */
@Component
public class AccountConvert {

    public Account convert(SysBaseAccount sysBaseAccount) {
        Account account = new Account(sysBaseAccount.getId(), sysBaseAccount.getUsername(), sysBaseAccount.getPassword(),
                sysBaseAccount.getAgencyCode(), sysBaseAccount.getDepartmentCode(), sysBaseAccount.getName(), sysBaseAccount.getContactNumber(), sysBaseAccount.getEmail(),
                sysBaseAccount.getDescription(), sysBaseAccount.getAccountType(), sysBaseAccount.getVersion());
        return account;
    }

    public SysBaseAccount convert(Account account) {
        SysBaseAccount sysBaseAccount = new SysBaseAccount();
        BeanUtils.copyProperties(account, sysBaseAccount);
        sysBaseAccount.setAccountType(account.getAccountType().getIndex());
        return sysBaseAccount;
    }
}
